﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Microsoft.Popfly.GameCreator.GameEngine
{
    public abstract class PropertyHolder
    {
        // TODO: add tracking for holder type?
        private Dictionary<String, Object> m_properties = new Dictionary<String, Object>();
        public virtual Object GetValue(String propertyName)
        {
            Object retVal;
            if (m_properties.TryGetValue(propertyName, out retVal))
            {
                return retVal;
            }
            else
            {
                return 0.0;
            }
        }
        public virtual void SetValue(String propertyName, Object value)
        {
            double doubleResult;
            Type type = value.GetType();

            if (type.Equals(typeof(string)))
            {
                if (Double.TryParse((string)value, out doubleResult))
                {
                    m_properties[propertyName] = doubleResult;
                    return;
                }
            }

            m_properties[propertyName] = value;
        }
        #region CustomCodeSupport
        Dictionary<string, object> customDict = new Dictionary<string, object>();

#if !PHONE
        [SpecialName]
#endif
        public object GetBoundMember(string name)
        {
            object retVal;
            customDict.TryGetValue(name, out retVal);
            return retVal;
        }

#if !PHONE
        [SpecialName]
#endif
        public void SetMemberAfter(string name, object value)
        {
            customDict[name] = value;
        }


        #endregion
    }
}
